﻿<cfsilent>
	<cfscript>
		
		sql = "SELECT  a.course_name,a.course_english,
					   a.course_credit,a.period,
					   a.period_theory,a.period_practice,
					   a.period_computer,a.period_week,
					   b.institute_name,c.cat_name,
					   a.course_code
				FROM t_course a  
					 INNER JOIN t_institute b ON b.institute_id = a.institute_id 
					 INNER JOIN t_course_catalog c ON c.cat_id = a.cat_id 
				ORDER BY b.institute_name, a.course_name ASC ";
		queryObj = new Query( datasource=application.dnsSlave ); 
		rs_course= queryObj.execute( sql=sql ).getResult();	
		
		temFile = GetTempDirectory() & createUUID() & ".xls";
		downFile = URLEncodedFormat("课程基础信息", "utf-8");
		
		excel = getProperty("serviceFactory").getBean("spreadSheetObject");
		
		/* 创建工作簿 */
		spreadsheetObj = excel.SpreadSheetNew("课程", false);
		
		/* 添加表头 */
		excel.SpreadsheetAddrow(spreadsheetObj, "课程,英文名称,学分,总学时,理论学时,实践学时,上机学时,排课周学时,任课单位,课程类型,课程号");
		
		row = 1;
		
		for ( a=1; a LTE rs_course.recordCount; a++ ) {
			
			row++;
			
			/* 构建课程信息 */
			rowData = rs_course["course_name"][a]
						& ","
						& rs_course["course_english"][a]
						& ","
						& numberFormat( rs_course["course_credit"][a], "_.__") 
						& ","
						& rs_course["period"][a]
						& ","
						& rs_course["period_theory"][a] 
						& ","
						& rs_course["period_practice"][a] 
						& ","
						& rs_course["period_computer"][a] 
						& ","
						& rs_course["period_week"][a] 
						& ","
						& rs_course["institute_name"][a] 
						& ","
						& rs_course["cat_name"][a]
						& ","
						& rs_course["course_code"][a];
				
			/* 写入课程信息*/
			excel.SpreadsheetAddrow(spreadsheetObj, rowData);

		}
		
		excel.SpreadSheetWrite(spreadsheetObj, temFile, true);
		
	</cfscript>

	<cfheader name="Content-Disposition" value="attachment; filename=#downFile#.xls" />
	<cfcontent file="#temFile#" reset="yes" type="application/msexcel" deletefile="yes" />	
	
</cfsilent>